<template>
	<view class="l_pages">
		<jnavbar :title="form.name"></jnavbar>
		<view class="page_container tab_page_container" style="overflow: hidden;position: relative;">
			<view class="content">
				<image v-if="form.other.prize_bg_img" :src="form.other.prize_bg_img" mode="widthFix" style="width: 750rpx;"></image>
				<block v-else>
					<vimage v-if="form.style == 1" mode="widthFix" imgtype="1" src="static/images/prize_bg.png"></vimage>
					<vimage v-if="form.style == 2" mode="widthFix" imgtype="1" src="static/images/scratch_bg.png"></vimage>
				</block>
				<view class="more_box" @click="tojump">
					中奖列表
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="view_content" :style="'top:' + form.other.box_top * 2 + 'rpx'" v-if="form.style == 1">
					<turntable @win="getWinPrize" @init="initprice" :form="form" :list="list" :winList="winList"></turntable>
					<view style="color:#fff;margin:0 auto;text-align:center;margin-top:10rpx">今日免费次数：{{ form.dnumber }}次,</view>
					<view style="color:#fff;margin:0 auto;text-align:center;margin-top:10rpx">今日次数：{{ form.get_number }}/{{ form.limit }}次</view>

					<view class="rule_text"><text @click="show = true">活动规则</text></view>
				</view>
				<view class="view_content" :style="'top:' + form.other.box_top * 2 + 'rpx'" v-if="form.style == 2">
					<scratch :canvasLeft="canvasLeft" ref="scratchRef" @win="getWinPrize" :form="form" :list="list" :winList="winList"></scratch>

					<view class="rule_text"><text @click="show = true">活动规则</text></view>
				</view>
				<vimage class="foregImg" mode="widthFix" v-if="form.other.foreg_img" :src="form.other.foreg_img"></vimage>

				<u-popup v-model="show" mode="center">
					<view class="show_view">
						<view class="u-font-lg">活动规则</view>
						<scroll-view class="show_content" scroll-y="true">
							<u-parse :tag-style="style" :domain="baseUrl" :html="form.other.text" :show-with-animation="true"></u-parse>
						</scroll-view>

						<view class="btn" @click="show = false"><u-icon name="close"></u-icon></view>
					</view>
				</u-popup>
				<u-popup v-model="showlottery" mode="center">
					<view class="show_lottery_view">
						<view class="view_content">
							<vimage mode="widthFix" imgtype="1" src="static/images/i_img.png"></vimage>
							<view class="view_title">好可惜！差点就中了!</view>
							<view class="view_btn" @click="showlottery = false">再抽一次</view>
						</view>
						<view class="btn" @click="showlottery = false"><u-icon name="close" size="30"></u-icon></view>
					</view>
				</u-popup>
				<u-popup v-model="showno" mode="center">
					<view class="show_no_view">
						<view class="view_content">
							<view class="item" v-if="showno">
								<vimage class="item_img" mode="widthFix" :src="winList.image"></vimage>
								<view class="item_txt">
									<view v-if="winList.type !== 1">
										<view>{{ winList.name }}</view>
										<view class="l_title">数量：{{ winList.number }}</view>
									</view>
								</view>
							</view>
							<view class="view_btn" @click="tojump">前往中奖列表</view>
						</view>
						<view class="btn" @click="showno = false"><u-icon name="close" size="30"></u-icon></view>
					</view>
				</u-popup>
			</view>
		</view>
		<nloading></nloading>
	</view>
</template>

<script>
import scratch from './components/scratch.vue';
import turntable from './components/turntable.vue';
import base from '@/common/baseUrl.js';
import http from '@/common/http.js';
import util from '@/common/util.js';
import {mapState, mapMutations} from 'vuex';
export default {
	data() {
		return {
			list: [
				// '恭喜 187****8888 获得刮刮乐奖品8元代金券',
				// '恭喜 187****1111 获得刮刮乐奖品8元代金券',
				// '恭喜 187****2222 获得刮刮乐奖品8元代金券',
				// '恭喜 187****6666 获得刮刮乐奖品8元代金券'
			],
			form: {
				prizelist: [],
				other: [],
				style: 1
			},
			start_time: '',
			end_time: '',
			showToast: false,
			show: false,
			showlottery: false,
			showno: false,
			isTrue: false,
			update_time: '',

			img_url: '',
			winList: {},
			id: '',
			style: {
				// 字符串的形式
				p: 'word-wrap : break-word'
			},
			isloading: false
			// canvasLeft:99999
		};
	},
	components: {
		scratch,
		turntable
	},

	onLoad(e) {
		if (e) {
			this.id = e.id;
		}
		this.changeloading({loading: true});
	},

	mounted() {
		this.getPrize();
	},
	computed: {
		prize_bg() {
			return "background-image:url('" + this.form.other.prize_bg_img + "');";
		},
		baseUrl() {
			return util.geturl(base.baseUrl);
		},
		canvasLeft() {
			if (this.show || this.showlottery || this.showno) {
				return 99999;
			} else {
				if (!this.isloading) {
					return 99999;
				} else {
					return 0;
				}
			}
		},
		...mapState({
			oss: state => state.oss
		})
	},
	methods: {
		//获取抽奖信息
		getPrize() {
			const _this = this;
			http('/lottery/find/' + this.id, 'get').then(res => {
				this.update_time = res.data.msg.update_time;
				this.form = res.data.msg.Config;
				this.form.dnumber = res.data.msg.total_number;
				this.form.get_number = res.data.msg.get_number;
				this.form.config = JSON.parse(this.form.config);
				this.form.other = JSON.parse(res.data.msg.Config.other);
				this.form.other.prize_bg_img = util.getimgurl(this.form.other.prize_bg_img);
				this.form.other.prize_top_img = util.getimgurl(this.form.other.prize_top_img);
				if (this.form.style == 2) {
					this.$nextTick(function() {
						this.$refs.scratchRef.drawInit();
					});
					setTimeout(() => {
						_this.isloading = true;
						_this.changeloading({loading: false});
					}, 600);
				} else {
					setTimeout(() => {
						_this.changeloading({loading: false});
					}, 300);
				}
			});
		},
		initprice() {
			this.winList = {};
		},
		// 抽奖结果
		getWinPrize(bal, type) {
			if (bal) {
				if (this.winList.uniqid == '000000') {
					this.showlottery = true;
				} else {
					this.showno = true;
				}
			} else {
				let data = {
					style: this.form.style,
					update_time: this.update_time,
					type
				};
				http('/lottery/lottery', data, 'post').then(res => {
					this.winList = res.data.msg;
					this.getPrize();
				});
			}
		},
		tojump() {
			this.Jumpurl({
				link: './prizelist',
				type: 1
			});
		},

		againScratch() {
			this.$refs.scratchRef.again();
		}
	}
};
</script>

<style lang="scss" scoped>
.content {
	width: 750rpx;
	// height: 100vh;
	display: block;
	background-image: none;
	background-repeat: no-repeat;
	background-position: center center;
	background-size: cover;

	.more_box {
		width: 160rpx;
		height: 55rpx;
		display: block;
		background: rgba($color: #000000, $alpha: 0.2);
		position: absolute;
		top: 80rpx;
		z-index: 99;
		right: 0;
		border-radius: 60rpx 0 0 60rpx;
		line-height: 55rpx;
		text-align: center;
		color: #fff;
		font-size: 24rpx;
	}

	> .view_content {
		width: 100%;
		position: absolute;
		z-index: 2;
		top: 560rpx;

		.item_box {
			position: relative;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			text-align: center;
			padding: 5rpx;
		}
	}

	.list {
		margin-top: 100rpx;
	}
}

.rule_text {
	color: #fff;
	width: 150rpx;
	margin: 40rpx auto 0;
	border-bottom: #fff solid 2px;
	display: block;
	text-align: center;
}

.show_view {
	width: 640rpx;
	height: 940rpx;
	display: block;
	background: #fff;
	border-radius: 20rpx;
	// background: url('https://jzwl365.oss-cn-beijing.aliyuncs.com/static/images/rule_bg.png') no-repeat;
	padding: 20rpx 30rpx;
	position: relative;
	.u-font-lg {
		font-weight: 600;
		text-align: center;
		padding: 20rpx 0;
	}
	.show_content {
		height: 800rpx;
	}
	.btn {
		text-indent: 0em;
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		width: 60rpx;
		height: 60rpx;
		font-size: 28rpx;
		color: #fff;
		border: solid 4rpx #fff;
		bottom: 0rpx;
		text-align: center;
		line-height: 52rpx;
		border-radius: 50%;
	}
}

.show_lottery_view {
	width: 600rpx;
	height: 800rpx;
	display: block;
	position: relative;

	.view_content {
		padding: 40rpx 120rpx;
		font-size: 24rpx;
		background: -webkit-linear-gradient(#fef594, #ffc93e);
		background: linear-gradient(#fef594, #ffc93e);
		border-radius: 30rpx;

		.view_title {
			text-align: center;
			margin: 40rpx 0;
			font-size: 38rpx;
			color: #963b18;
			font-weight: bold;
		}

		.view_btn {
			width: 240rpx;
			height: 70rpx;
			line-height: 70rpx;
			text-align: center;
			margin: 40rpx auto;
			font-size: 32rpx;
			color: #fff;
			background: #ff4a37;
			border-radius: 50rpx;
		}

		image {
			width: 100%;
		}
	}

	.btn {
		text-indent: 0em;
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		width: 60rpx;
		height: 60rpx;
		font-size: 28rpx;
		color: #fff;
		border: solid 4rpx #fff;
		bottom: 0rpx;
		text-align: center;
		line-height: 52rpx;
		border-radius: 50%;
	}
}

.show_no_view {
	width: 600rpx;
	height: 650rpx;
	display: block;
	position: relative;

	.view_content {
		padding: 260rpx 30rpx 50rpx;
		font-size: 24rpx;
		background: url('https://jzwl365.oss-cn-beijing.aliyuncs.com/static/images/letter_img.png') no-repeat;
		background-size: 100%;
		border-radius: 30rpx;

		.item {
			display: flex;
			align-items: center;
			background: #fff;
			border-radius: 15rpx;
			padding: 20rpx 30rpx;
			position: relative;

			.item_txt {
				font-size: 28rpx;
				color: #333333;
				padding-left: 20rpx;
				width: 320rpx;

				.l_title {
					color: #d2d2d2;
					font-size: 24rpx;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}

			/deep/.item_img {
				width: 120rpx;
				height: 120rpx;
				border-radius: 15rpx;
			}
		}

		.item:before {
			content: '';
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			left: -15rpx;
			border-radius: 50%;
			background: -webkit-linear-gradient(#feec83, #fee371);
			background: linear-gradient(#feec83, #fee371);
		}

		.item:after {
			content: '';
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			right: -15rpx;
			border-radius: 50%;
			background: -webkit-linear-gradient(#feec83, #fee371);
			background: linear-gradient(#feec83, #fee371);
		}

		.view_title {
			text-align: center;
			margin: 40rpx 0;
			font-size: 38rpx;
			color: #963b18;
			font-weight: bold;
		}

		.view_btn {
			height: 80rpx;
			line-height: 70rpx;
			text-align: center;
			margin-top: 15rpx;
			font-size: 32rpx;
			color: #fff;
			background: #ee472e;
			border-radius: 50rpx;
			box-shadow: 0 -10rpx 0 #cd0413 inset;
		}

		image {
			width: 100%;
		}
	}

	.btn {
		text-indent: 0em;
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		width: 60rpx;
		height: 60rpx;
		font-size: 28rpx;
		color: #fff;
		border: solid 4rpx #fff;
		bottom: 0rpx;
		text-align: center;
		line-height: 52rpx;
		border-radius: 50%;
	}
}

.foregImg {
	width: 100%;
	position: absolute;
	bottom: 0;
	z-index: 999;
}
</style>
